package com.frxuexi.shop.viewmodel

import com.frxuexi.lib_base.http.RequestType
import com.frxuexi.lib_base.http.ShopApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.shop.intent.OrderIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class OrderViewModel @Inject constructor(val apiService: ShopApiService):BaseViewModel<OrderIntent>(){
    override fun handleIntent(it: OrderIntent) {
        when(it){
            is OrderIntent.getOrders->httpRequest(apiService.getOrders(it.type))
            is OrderIntent.cancelOrder->httpRequest(apiService.cancelOrder(it.id),RequestType.DELETE)
            is OrderIntent.payOrder->httpRequest(apiService.payOrder(toBody(it.item)),RequestType.UPDATE)
            is OrderIntent.addComment->httpRequest(apiService.addComment(toBody(it.item)),RequestType.ADD)
            is OrderIntent.upload->httpRequest(apiService.upload(toMultiBody(it.name,it.path).parts,"product",1),RequestType.UPLOAD)
            is OrderIntent.refundOrder->httpRequest(apiService.refundOrder(toBody(it.item)),RequestType.REFUND)
        }
    }

}